<!-- 新增编辑车辆 -->
<template>
  <el-dialog
    title="新增车辆"
    width="40%"
    :visible="dialogVisible"
    @close="close"
  >
    <el-form ref="form" :rules="rules" :model="form">
      <el-form-item label="车辆类型">
        <el-select v-model="form.truckTypeId" placeholder="请选择">
          <el-option
            v-for="item in carTypeList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="车牌号码" prop="licensePlate">
        <el-input
          v-model="form.licensePlate"
          placeholder="请输入车牌号码"
        ></el-input>
      </el-form-item>
      <el-form-item label="GPS设备ID" prop="deviceGpsId">
        <el-input
          v-model="form.deviceGpsId"
          placeholder="请输入GPS设备ID"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="upDataMsg">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { truckTypeAdd } from '@/api/transit'
export default {
  name: 'VehicleAdd',
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    carTypeList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      form: {
        licensePlate: '', // 车牌号
        deviceGpsId: '', // GPS设备
        truckTypeId: '' // 车辆类型ID
      },
      rules: {
        licensePlate: [
          { required: true, message: '请输入车牌号', trigger: 'blur' }
        ],
        deviceGpsId: [
          { required: true, message: '请输入GPSID', trigger: 'blur' }
        ]
      }
      // carTypeDataList: []
    }
  },
  created() {},
  methods: {
    close() {
      this.$emit('update:dialogVisible', false)
      this.$refs.form.resetFields()
    },
    // 点击确定添加
    async upDataMsg() {
      await truckTypeAdd(this.form)
      this.close()
      this.$emit('updateTruck')
      // this.$emit('update:DialogVisible', false)
    }
  }
}
</script>
<style scoped lang="scss">
/deep/ .el-dialog__body {
  padding: 40px 50px 0 20px !important;
}
</style>
